import requests


class SendMethod:
    @staticmethod
    def send_method(method,url,params=None,data=None,json=None,headers=None):

        if method == "get":
            response =requests.get(url=url,params=params,headers=headers)

        elif method == "post":
            response = requests.post(url=url,data=data,json=json,headers=headers)
        else:
            response = None
            print("请求方法错误")

        result = {}
        if response is not None:
            result["status_code"] = response.status_code
            result["headers"] = response.headers
            result["body"] = response.json()
            result["response_time"] = int(response.elapsed.microseconds / 1000)
            return result
        else:
            return response

if __name__=='__main__':
    url = "http://47.108.206.100:8080/admin/login"
    method = "post"

    body = {
        "username":"admin",
        "password":"macro123"
    }

    print(SendMethod.send_method(method=method, url=url, json=body))
